package com.zhang.controller;


import com.zhang.service.ShoppingCategory2Service;
import com.zhang.units.Result;
import com.zhang.vo.Category1Vo;
import com.zhang.vo.Category2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@RestController
@RequestMapping("/shopping-category2")
public class ShoppingCategory2Controller {

    @Autowired
    private ShoppingCategory2Service shoppingCategory2Service;

    /**
     * 显示二级类目列表
     */
    @GetMapping("/category2_name")
    public Result category2Name(@RequestParam("category2Name") String category2Name,
                                @RequestParam("pageNo") int pageNo,
                                @RequestParam("pageSize")int pageSize){
        return Result.result200(shoppingCategory2Service.category2Name(category2Name,pageNo,pageSize));
    }
    /**
     * 处理显示或者隐藏二级类目
     */
    @GetMapping("/change_value2")
    public  Result changeValue(@RequestParam("category2Id") String category2Id){
        return Result.result200(shoppingCategory2Service.changeValue(category2Id));
    }
    /**
     * 详细信息
     */
    @GetMapping("/get_category2")
    public Result getCategory(@RequestParam("category2Id") String category2Id){
        return Result.result200(shoppingCategory2Service.getCategory(category2Id));
    }
    /**
     * 新增二级目录
     */
    @GetMapping("/add_category2")
    public Result addCategory(@RequestParam("category2Name") String category2Name,
                               @RequestParam("category2Record")String category2Record,
                                @RequestParam("category1Id") String category1Id){
        return Result.result200(shoppingCategory2Service.addCategory2(category2Name,category2Record,category1Id));
    }
    /**
     *修改二级类目
     */
    @PostMapping("/update_category2")
    public Result updateCategory1(@RequestBody Category2Vo category2Vo){
        return Result.result200(shoppingCategory2Service.updateCategory2(category2Vo.getId(), category2Vo.getCategory2Name(), category2Vo.getCategory2Record(),category2Vo.getCategory1Id()));
    }
    /**
     * 删除二级类目
     */
    @GetMapping("/delete_category3")
    public  Result deleteCategory1(@RequestParam("category2Id") String category2Id){
        return Result.result200(shoppingCategory2Service.removeById(category2Id));
    }
    /**
     * 删除二级类目
     */
    @GetMapping("/delete_category4")
    public  Result deleteCategory2(@RequestParam("category2Ids") List<String> category2Ids){
        return Result.result200(shoppingCategory2Service.removeByIds(category2Ids));
    }

}

